﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Portal
{
    public class CodeSmithHelper
    {

        public string FirstReplace(string target, string old, string replace)
        {
            if (string.IsNullOrEmpty(target) || string.IsNullOrEmpty(((target ?? "").Trim())))
            {
                return target;
            }
            if (string.IsNullOrEmpty(old) || string.IsNullOrEmpty(((old ?? "").Trim())))
            {
                return target;
            }
            if (target.IndexOf(old, StringComparison.Ordinal) == 0)
            {
                return target.Remove(0, old.Length).Insert(0, replace);
            }
            return target;
        }

        public string BaseObjectInfterface(bool isBase, bool isInterface, string baseObject, string inter)
        {
            var baseObjectInfterface = string.Empty;
            if (string.IsNullOrEmpty(baseObject) || string.IsNullOrEmpty(((baseObject ?? "").Trim())))
            {
                return "";
            }
            if (string.IsNullOrEmpty(inter) || string.IsNullOrEmpty(((inter ?? "").Trim())))
            {
                return "";
            }
            if (isBase)
            {
                baseObjectInfterface = ":" + baseObject;
            }
            if (isInterface)
            {
                if (string.IsNullOrEmpty(baseObjectInfterface))
                {
                    return ":" + inter;
                }
                baseObjectInfterface = baseObjectInfterface + "," + inter;
            }
            return baseObjectInfterface;
        }
        public string BaseObjectInfterface(bool isBase, bool isInterface, string baseObject, string inter, bool isGenerics, string generics)
        {
            var baseObjectInfterface = string.Empty;
            if (string.IsNullOrEmpty(baseObject) || string.IsNullOrEmpty(((baseObject ?? "").Trim())))
            {
                return "";
            }
            if (string.IsNullOrEmpty(inter) || string.IsNullOrEmpty(((inter ?? "").Trim())))
            {
                return "";
            }
            if (isBase)
            {
                baseObjectInfterface = ":" + baseObject;
            }
            if (isInterface)
            {
                if (string.IsNullOrEmpty(baseObjectInfterface))
                {
                    return ":" + inter;
                }
                baseObjectInfterface = baseObjectInfterface + "," + inter;
            }
            return baseObjectInfterface;
        }
        public bool IsExist(string[] list, string value)
        {
            if (list == null)
                return false;
            if (string.IsNullOrEmpty(value) || string.IsNullOrEmpty(((value ?? "").Trim())))
            {
                return false;
            }
            return Array.IndexOf(list, value) != -1;
        }
    }



}
